﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Dsl.Ped.Controls.ButtonActionSelector">

    <Style TargetType="{x:Type local:ButtonActionSelectorControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ButtonActionSelectorControl}">
                    <Button VerticalAlignment="Center"
                            Content="{TemplateBinding Content}"
                            Margin="{TemplateBinding Margin}"
                            Padding="{TemplateBinding Padding}"
                            Background="{TemplateBinding Background}"
                            Name="PART_MainButton">
                        <Button.ContextMenu>
                            <ContextMenu Name="PART_MainContextMenu" ItemsSource="{TemplateBinding Commands}">
                                <ContextMenu.ItemContainerStyle>
                                    <Style TargetType="{x:Type MenuItem}">
                                        <Setter Property="Header" Value="{Binding Name}"/>
                                        <Setter Property="Command" Value="{Binding}"/>
                                        <Setter Property="CommandParameter" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ButtonActionSelectorControl}, Path=CommandParameter}"/>
                                    </Style>
                                </ContextMenu.ItemContainerStyle>
                            </ContextMenu>
                        </Button.ContextMenu>
                    </Button>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>